|
|
|
|
|
|
|
You will set these data control values in a separate procedure, called OpenDB. To create a new procedure in Visual Basic, double-click anywhere on the form in order to bring up a Visual Basic code window. Now select Add Procedure . . . from the Visual Basic Tools menu. You'll see a dialog box that asks you for the name of the procedure (see Figure 4.1). |
|
|
|
|
|
|
|
|
Figure 4.1.
Creating a new Visual Basic procedure. |
|
|
|
|
|
|
|
|
Enter OpenDB. Make sure the radio button for Sub is selected and then click OK. You now see the new Visual Basic procedure header and footer, ready for you to enter your program code. |
|
|
|
|
|
|
|
|
The following procedure sets the DatabaseName property of the data control on the current form. Please note where we have entered the location of the BOOKS5.MDB file. You may need to substitute a different path if you installed the database elsewhere on your system. |
|
|
|
|
| |
|
|
|
|
If you install your data files in the same directory as your program files, you can use the App.Path command to identify the data file location. App.Path can be used as part of the database name to identify the database location without having to know the name of the directory in which it is stored. The Path property of the App object returns the drive and directory in which the project has been stored. |
|
|
|
|
|
|
|
|
This methodology is useful when building applications that will be distributed across an organization, or to multiple organizations. App.Path allows you to utilize setup programs that let the user select the directory in which to install the program files. Your data files will be found as long as they are stored with the program files. |
|
|
|
|
|
|
|
|
As an illustration, if we had installed our BOOKS5.MDB file in the same directory as we saved the current project, we could substitute: |
|
|
|
|
|
|
|
|
cDBName = App.Path + "\books5.mdb" |
|
|
|
|
|
|
|